package com.example.administrator.food.adapter;/**
 * Created by Administrator on 2016/9/28.
 */

import android.content.Context;
import android.view.LayoutInflater;
import android.widget.BaseAdapter;

import java.util.ArrayList;
import java.util.List;

/**
 * User: 张莉璟(2283465007@qq.com)
 * Date: 2016/09/28
 * Time: 10:21
 * progject: YueFoodHome
 * Describe： 总适配器
 */
public abstract class MBaseAdapter<T>extends BaseAdapter {
    private List<T> data;
    private LayoutInflater inflater;
    private Context context;

    public MBaseAdapter(Context context, LayoutInflater inflater, List<T> data) {
        this.data =new ArrayList<>();
        inflater=LayoutInflater.from(context);
        this.context=context;
    }

    public Context getContext() {
        return context;
    }

    public LayoutInflater getInflater() {
        return inflater;
    }

    public  void addAll(List<T> mdata){
        data.addAll(mdata);
        notifyDataSetChanged();
    }
    public  void  clear(){
        data.clear();
        notifyDataSetChanged();
    }
    @Override
    public int getCount() {
        return data!=null?data.size():0;
    }

    @Override
    public T getItem(int position) {
        return data.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

}
